// DlgTextProperty.cpp : implementation file
//

#include "stdafx.h"
#include "MotionControlSoftware.h"
#include "DlgTextProperty.h"
#include "afxdialogex.h"
#include "GDI/Block.h"


// CDlgTextProperty dialog

IMPLEMENT_DYNAMIC(CDlgTextProperty, CDialogEx)

CDlgTextProperty::CDlgTextProperty(CWnd* pParent /*=NULL*/)
	: CDialogEx(CDlgTextProperty::IDD, pParent)
{
	m_TextBlock = NULL;
}

CDlgTextProperty::~CDlgTextProperty()
{
}

void CDlgTextProperty::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_MFCFONTCOMBO_Style, m_FontCombo);
	DDX_Control(pDX, IDC_RADIO_TrueType, m_radioTrueType);
	DDX_Control(pDX, IDC_EDIT_Text, m_EditText);
}


BEGIN_MESSAGE_MAP(CDlgTextProperty, CDialogEx)
	ON_WM_SHOWWINDOW()
	ON_CBN_SELCHANGE(IDC_MFCFONTCOMBO_Style, &CDlgTextProperty::OnFontSelectionChange)
	ON_EN_CHANGE(IDC_EDIT_Text, &CDlgTextProperty::OnEditTextChanged)
END_MESSAGE_MAP()


// CDlgTextProperty message handlers

BOOL CDlgTextProperty::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	ShowData();
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgTextProperty::OnShowWindow(BOOL bShow, UINT nStatus)
{
	CDialogEx::OnShowWindow(bShow, nStatus);
	if (bShow)
	{
		m_radioTrueType.SetCheck(1);
		ShowData();
	}
}

bool CDlgTextProperty::UpdateParam()
{
	UpdateData();
	if (m_TextBlock != NULL)
	{
		CGraph* pGraph = m_TextBlock->GetHead();
		CText* pText = (CText*) pGraph->GetHead();
		pText->SetFont(m_strFont);
		pText->SetText(m_strText);	
		return true;
	}
	return false;
}

void CDlgTextProperty::OnFontSelectionChange() {
	CMFCFontInfo* pFontDesc = m_FontCombo.GetSelFont();
	if (pFontDesc)
		m_strFont = pFontDesc->m_strName;
}

void CDlgTextProperty::OnEditTextChanged() {
	m_EditText.GetWindowText(m_strText); 
}

void CDlgTextProperty::ShowData()
{
	if (m_TextBlock != NULL)
	{
		CGraph* pGraph = m_TextBlock->GetHead();
		if (pGraph)
		{
			CText* pText = (CText*)(pGraph->GetHead());
			m_EditText.SetWindowText(pText->GetText());
			m_FontCombo.SelectFont(pText->GetFont());
			m_strFont = pText->GetFont();
			m_strText = pText->GetText();
		}
		else
		{
			AfxMessageBox(_T("showdata"));
		}
	}
	UpdateData(FALSE);
}
